<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Google 地图 API 示例: 反向地图解析</title>
    <script src="http://ditu.google.cn/maps?hl=zh-CN&amp;file=api&amp;v=2&amp;key=ABQIAAAAPTwhF4vlVXrO7ZGOjA9sOxTqQ5WtUwE0C8FR1hRk-yj3qFOmhhR6esbxCerNyfzApAoTJGfOHzcKCQ&sensor=false"></script>
    <script type="text/javascript">
      var map;
      var geocoder;
      var address;

      function initialize() {
        if (GBrowserIsCompatible()) { 
         map = new GMap2(document.getElementById("map_canvas"), {size:new GSize(400, 300)});
         map.setCenter(new GLatLng(39.917, 116.397), 14);
         map.addControl(new GSmallMapControl());
         GEvent.addListener(map, "click", getAddress);
         geocoder = new GClientGeocoder();
        }
      }
    
      function getAddress(overlay, latlng) {
        if (latlng != null) {
          address = latlng;
          geocoder.getLocations(latlng, showAddress);
        }
      }

      function showAddress(response) {
        map.clearOverlays();
        if (!response || response.Status.code != 200) {
          alert("嗯，你点击的这个地方还没有准确地址！"+"状态码（Status Code）:" + response.Status.code);
        } else {
          place = response.Placemark[0];
          point = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
          marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(
            '<div style="font-size:13px;">' +
            '<b>你现在所点击的地址:</b><br/>' + place.address + '<br/><br/>' +
            '<b>准确度:</b>' + place.AddressDetails.Accuracy + '</div>');
        }
      }
    </script>
   </head>
   <body onload="initialize()">
    <div id="map_canvas"></div>
  </body>
</html>